<template>
  <div class="page-container">
    <h1 class="page-title">系统概览</h1>
    
    <el-row :gutter="20">
      <el-col :span="12">
        <el-card shadow="hover" class="dashboard-card">
          <div class="card-header">
            <span>用户统计</span>
          </div>
          <div class="dashboard-card-content user-stats">
            <div class="stat-item">
              <div class="stat-icon">
                <i class="el-icon-user"></i>
              </div>
              <div class="stat-info">
                <div class="stat-title">普通用户</div>
                <div class="stat-value">{{ stats.userCount || 0 }}</div>
              </div>
            </div>
            <div class="stat-item">
              <div class="stat-icon admin-icon">
                <i class="el-icon-s-custom"></i>
              </div>
              <div class="stat-info">
                <div class="stat-title">管理员</div>
                <div class="stat-value">{{ stats.adminCount || 0 }}</div>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover" class="dashboard-card">
          <div class="card-header">
            <span>句子统计</span>
          </div>
          <div class="dashboard-card-content">
            <div class="card-item">
              <div class="card-item-title">总句子数</div>
              <div class="card-item-value">{{ stats.sentenceCount || 0 }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover" class="dashboard-card">
          <div class="card-header">
            <span>录音统计</span>
          </div>
          <div class="dashboard-card-content">
            <div class="card-item">
              <div class="card-item-title">总录音数</div>
              <div class="card-item-value">{{ stats.recordingCount || 0 }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 新疆民族风格装饰 -->
    <div class="xinjiang-decoration">
      <div class="pattern"></div>
      <div class="pattern pattern-bottom"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Dashboard',
  data() {
    return {
      stats: {
        userCount: 0,
        adminCount: 0,
        sentenceCount: 0,
        recordingCount: 0
      },
      loading: false,
      playerVisible: false,
      showDebugInfo: false
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    async fetchData() {
      this.loading = true
      try {
        console.log('Dashboard: 开始获取系统统计数据')
        // 获取系统统计数据
        const stats = await this.$store.dispatch('fetchStats')
        console.log('Dashboard: 系统统计数据获取成功:', stats)
        console.log('Dashboard: 原始数据结构:', JSON.stringify(stats))
        this.stats = stats
      } catch (error) {
        console.error('Dashboard: 获取数据失败:', error)
        // 尝试单独获取系统统计数据
        try {
          console.log('Dashboard: 尝试单独获取系统统计数据')
          const stats = await this.$store.dispatch('fetchStats')
          console.log('Dashboard: 系统统计数据单独获取成功')
          this.stats = stats
        } catch (statsError) {
          console.error('Dashboard: 系统统计数据获取失败:', statsError)
        }
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style scoped>
.dashboard-card {
  height: 180px;
}

.card-header {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 20px;
}

.dashboard-card-content {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 100%;
}

/* 用户统计卡片的特殊样式 */
.user-stats {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.stat-item {
  display: flex;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  transition: all 0.3s;
  width: 45%;
}

.stat-item:hover {
  background-color: var(--bg-secondary);
}

.stat-icon {
  background-color: rgba(139, 156, 160, 0.2);
  color: var(--primary);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
}

.stat-icon i {
  font-size: 24px;
}

.admin-icon {
  background-color: rgba(209, 182, 163, 0.2);
  color: var(--secondary);
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-title {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.stat-value {
  font-size: 24px;
  font-weight: 500;
  color: var(--primary);
}

.card-item {
  text-align: center;
  margin-bottom: 10px;
}

.card-item-title {
  font-size: 14px;
  color: var(--text-secondary);
}

.card-item-value {
  font-size: 28px;
  font-weight: 500;
  color: var(--primary);
  margin-top: 10px;
}

.audio-player-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 0;
}

.xinjiang-decoration {
  margin-top: 40px;
  position: relative;
  min-height: 60px;
}
.pattern {
  width: 100%;
  height: 24px;
  background: repeating-linear-gradient(90deg, #eab308 0 20px, #fff 20px 40px, #1e90ff 40px 60px, #fff 60px 80px);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 2px 8px 0 rgba(0,0,0,0.04);
}
.pattern-bottom {
  border-radius: 0 0 12px 12px;
  margin-top: 12px;
  transform: scaleY(-1);
}
</style> 